<?php 

// Desired folder structure
$structure = '../g-konten/fm/slide/'.$_GET['idmod'].'/';

// To create the nested structure, the $recursive parameter 
// to mkdir() must be specified.
if (!file_exists($structure)){
if (!mkdir($structure, 0777, true)) {
    die('Failed to create folders...');
}
}
// ...

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("UPDATE bannerplug_data SET id_module=%s, nama=%s, deskripsi=%s WHERE id=%s",
                       GetSQLValueString($_GET['idmod'], "int"),
                       GetSQLValueString($_POST['nama'], "text"),
                       GetSQLValueString($_POST['deskripsi'], "text"),
                       GetSQLValueString($_POST['id'], "int"));
if ($_FILES["foto"]["name"]<>''){
   
       move_uploaded_file($_FILES["foto"]["tmp_name"],
      '../g-konten/fm/slide/'.$_GET['idmod'].'/' . $_POST['gambar']);
      

mysql_select_db($database_konek, $konek);
$query_plugtext = "SELECT * FROM bannerplug WHERE id = '$_GET[idmod]' ORDER BY id ASC";
$plugtext = mysql_query($query_plugtext, $konek) or die(mysql_error());
$row_plugtext = mysql_fetch_assoc($plugtext);
$totalRows_plugtext = mysql_num_rows($plugtext);

// *** Include the class
	include("resize-class.php");

	// *** 1) Initialise / load image
	$resizeObj = new resize('../g-konten/fm/slide/'.$_GET['idmod'].'/' . $_POST['gambar']);

	// *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
	$resizeObj -> resizeImage($row_plugtext['width'], $row_plugtext['height'], 'crop');

	// *** 3) Save image
	$resizeObj -> saveImage('../g-konten/fm/slide/'.$_GET['idmod'].'/' . $_POST['gambar'], 100);
	
mysql_free_result($plugtext);
}

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($insertSQL, $konek) or die(mysql_error());

  $insertGoTo = "home.php?page=pluginview&p=".$_GET['p']."&root=data_module.php&idmod=".$_GET['idmod'];
 ?>
	
	 <script language="javascript">
  	<!--
     	    alert('Input Success')
			window.location = "<?php echo $insertGoTo ?>";
			
   	--></script>
	<?php
} 

mysql_select_db($database_konek, $konek);
$query_plugtext = "SELECT * FROM bannerplug_data WHERE id = '$_GET[id]' ORDER BY id ASC";
$plugtext = mysql_query($query_plugtext, $konek) or die(mysql_error());
$row_plugtext = mysql_fetch_assoc($plugtext);
$totalRows_plugtext = mysql_num_rows($plugtext);
?>
<a href="home.php?page=pluginview&p=<?php echo $_GET['p'] ?>&root=data_module.php&idmod=<?php echo $_GET['idmod'] ?>">&lt;&lt;back</a>
  <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <table width="100%" align="center">
      <tr valign="baseline">
        <td width="12%" align="left" valign="middle" nowrap="nowrap"><strong>Judul :</strong></td>
        <td width="88%"><input type="text" name="nama" class="form-control" value="<?php echo $row_plugtext['nama']; ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="middle" nowrap="nowrap"><strong>image :</strong></td>
        <td valign="top"><p>
          <label for="image"></label>
          <img src="<?php echo '../g-konten/fm/slide/'.$_GET['idmod'].'/' . $row_plugtext['image'];  ?>" width="100" /></p>
          <p>
          <input type="hidden" name="gambar" value="<?php echo $row_plugtext['image'];  ?>" />
            <input type="file" name="foto" id="foto" />
        </p></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap"><strong>deskripsi :</strong></td>
        <td><textarea name="deskripsi" cols="32" rows="5" class="form-control"><?php echo $row_plugtext['deskripsi']; ?></textarea></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
        <td><input type="submit" value="Submit" id="status-update-btn" class="btn btn-primary pull-right" /></td>
      </tr>
    </table>
    <input type="hidden" name="id" value="<?php echo $row_plugtext['id']; ?>" />
    <input type="hidden" name="MM_insert" value="form1" />
</form>
<?php

mysql_free_result($plugtext);
?>
